home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / etc / dhcp3 / dhclient-enter-hooks.d / samba < prev   
Text File  |  2009-10-02  |  2KB  |  78 lines

  1. #!/bin/sh
  2.  
  3. SAMBA_DHCP_CONF=/etc/samba/dhcp.conf
  4.  
  5. netbios_setup() {
  6.     # No need to continue if we're called with an unsupported option
  7.  
  8.     case $reason in
  9.     BOUND|RENEW|REBIND|REBOOT|EXPIRE|FAIL|RELEASE|STOP)
  10.         ;;
  11.     *)
  12.         return
  13.         ;;
  14.     esac
  15.  
  16.     umask 022
  17.  
  18.     local other_servers
  19.     other_servers==""
  20.     local serverlist
  21.     serverlist==""
  22.  
  23.     # the destination file won't exist yet on the first run after 
  24.     # installing samba
  25.     if [ -e $SAMBA_DHCP_CONF ]
  26.     then
  27.         # don't continue if no settings have changed
  28.         if [ "$new_netbios_name_servers" = "$old_netbios_name_servers" ] \
  29.            && [ "$new_netbios_scope" = "$old_netbios_scope" ] \
  30.            && [ -n "$new_netbios_name_servers" ]
  31.         then
  32.             return
  33.         fi
  34.  
  35.         # reparse our own file
  36.         other_servers=`sed -n -e"s/[[:space:]]$interface:[^[:space:]]*//g; \
  37.             s/^[[:space:]]*wins server[[:space:]]*=[[:space:]]*//pi" \
  38.             $SAMBA_DHCP_CONF`
  39.  
  40.         serverlist="$other_servers"
  41.     fi
  42.  
  43.     for server in $new_netbios_name_servers
  44.     do
  45.         serverlist="$serverlist $interface:$server"
  46.     done
  47.  
  48.     echo -n > ${SAMBA_DHCP_CONF}.new
  49.  
  50.     # If we're updating on failure/expire, AND there are no WINS
  51.     # servers for other interfaces, leave the file empty.
  52.     if [ -z "$other_servers" ]
  53.     then
  54.         if [ "$reason" = FAIL ] || [ "$reason" = EXPIRE ]
  55.         then
  56.             mv ${SAMBA_DHCP_CONF}.new $SAMBA_DHCP_CONF
  57.             return
  58.         fi
  59.     fi
  60.  
  61.     if [ -n "$serverlist" ]
  62.     then
  63.         echo "   wins server =$serverlist" >> ${SAMBA_DHCP_CONF}.new
  64.     fi
  65.     if [ -n "$new_netbios_scope" ]
  66.     then
  67.         echo "   netbios scope = $new_netbios_scope" >> ${SAMBA_DHCP_CONF}.new
  68.     fi
  69.     mv ${SAMBA_DHCP_CONF}.new $SAMBA_DHCP_CONF
  70.  
  71.     # reload the samba server
  72.     # We don't necessarily have the samba package installed. #414841
  73.     [ -x /etc/init.d/samba ] && /usr/sbin/invoke-rc.d samba reload
  74.  
  75. }
  76.  
  77. netbios_setup
  78.